/**
 * 
 */
package cn.softTank.BpelModelImpl;

import java.util.ArrayList;
import java.util.List;

import org.dom4j.Element;

import cn.softTank.BpelModel.Activity;
import cn.softTank.BpelModel.Flow;
import cn.softTank.BpelModel.Links;

/**
 * @author Yuzone (smartzxy@gmail.com)
 * 
 */
public class FlowImpl extends ActivityImpl implements Flow {

	private Links links;
	private List<Activity> activity;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * cn.softTank.BpelModel.Flow#addActivity(cn.softTank.BpelModel.Activity)
	 */
	@Override
	public void addActivity(Activity activity) {
		if(this.activity==null)
			this.activity=new ArrayList<Activity>();
		this.activity.add(activity);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.softTank.BpelModel.Flow#getActivity()
	 */
	@Override
	public List<Activity> getActivity() {
		return this.activity;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.softTank.BpelModel.Flow#getLinks()
	 */
	@Override
	public Links getLinks() {
		return links;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.softTank.BpelModel.Flow#removeActivityAt(int)
	 */
	@Override
	public void removeActivityAt(int index) {
		if(activity!=null && index<activity.size())
			activity.remove(index);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.softTank.BpelModel.Flow#setActivity(java.util.List)
	 */
	@Override
	public void setActivity(List<Activity> activity) {
		this.activity=activity;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.softTank.BpelModel.Flow#setLinks(cn.softTank.BpelModel.Links)
	 */
	@Override
	public void setLinks(Links links) {
		this.links=links;
	}

	@Override
	public Element toElement() {
		node=super.toElement();
		node.setName("flow");
		if(links!=null)
			node.add(links.toElement());
		if(activity!=null)
			for(int i=0; i<activity.size(); i++)
				node.add(activity.get(i).toElement());
		return node;
	}

	@Override
	public String toXml() {
		return null;
	}

}
